import React from 'react';
import { connect } from 'dva';
import styles from './Roommsg.css';

class Roommsg extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      peoplenum: this.props.data.peoplenum,
      roomnum: this.props.data.roomnum,
      player: this.props.data.player,
      householder: this.props.data.householder,
    };
  }
  componentWillReceiveProps(nextProps) {
    this.setState({
      peoplenum: nextProps.data.peoplenum,
      player: nextProps.data.player,
    });
  }
  render() {
    return (
      <div className={styles.root}>
        <p>
          <span>房间号：<em>{this.state.roomnum}</em></span>
          <span>在线人数：<em>{this.state.peoplenum}</em></span>
          <span>玩家：<em>{this.state.player}</em></span>
          <span>房主：<em>{this.state.householder}</em></span>
        </p>
      </div>
    );
  }

}

function mapStateToProps(state) {
  const data = state.ready.data;
  data.username = state.login.data.username;
  return { data };
}
export default connect(mapStateToProps)(Roommsg);
